//
//  AXMyJfVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/10/17.
//  Copyright © 2018年 tzhg. All rights reserved.
//

#import "AXMyJfVC.h"
#import "AXMyJfTableViewCell.h"
#import "AXMyJfModel.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "Header.h"
#import "UIViewController+HBD.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "XFStepView.h"
#import "IntegralViewController.h"
@interface AXMyJfVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray<AXMyJfModel *>  *modelsArray;
@property (nonatomic ,strong) UITableView *tableView;
///** 假图片数据 */
//@property (nonatomic, strong) NSArray<NSString *> *titleNames;
@property (nonatomic , strong) UIView *headView;
/** 上面的view */
@property (nonatomic , strong) UIView *jfView;
/** 用户图像*/
@property (nonatomic , strong) UIImageView *userImageView;
/** 用户名字*/
@property (nonatomic , strong) UILabel *userNameLabel;
/** 用户等级*/
@property (nonatomic ,strong) UILabel *jfGradeLabel;
/** 积分数量 */
@property (nonatomic , strong) UILabel *jfCountLabel;
/** 签到view */
@property (nonatomic , strong) UIView *qdView;
/** 进度条 */
@property (strong, nonatomic)XFStepView *stepView;
/** 签到按钮 */
@property (nonatomic , strong) UIButton *qdButton;

@end

@implementation AXMyJfVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    self.tableView.tableHeaderView = _headView;
    [_headView setNeedsLayout];
    [_headView layoutIfNeeded];//刷新布局
    _headView.frame = CGRectMake(0, NAVIGATION_HEIGHT, [UIScreen mainScreen].bounds.size.width, 200);//headView 的大小
    self.tableView.tableHeaderView = _headView;
    
}




- (void)creatView {

    /** 表头创建 */
    self.headView = [[UIView alloc]init];
    
    self.tableView = [[UITableView alloc]init];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXMyJfTableViewCell class] forCellReuseIdentifier:[AXMyJfTableViewCell reuseID]];
    [self.view addSubview:self.tableView];
    
    
    /** 上面的view */
    self.jfView = [[UIView alloc]init];
    [self.headView addSubview:self.jfView];
    /** 用户图像*/
    self.userImageView = [[UIImageView alloc]init];
    self.userImageView.cornerRadius = 40;
    /** 图片比例切 */
    self.userImageView.contentMode =UIViewContentModeScaleAspectFill;
    self.userImageView.clipsToBounds=YES;//
    self.userImageView.image = [UIImage imageNamed:@"xy.jpeg"];
    [self.jfView addSubview:self.userImageView];
    /** 用户名字*/
    self.userNameLabel = [[UILabel alloc]init];
    self.userNameLabel.text = @"李逍遥";
    self.userNameLabel.font = FONT_FOURTEEN;
    self.userNameLabel.textColor = COLOR_Gray;
    [self.jfView addSubview:self.userNameLabel];
    
    /** 用户等级*/
    self.jfGradeLabel = [[UILabel alloc]init];
    self.jfGradeLabel.text = @"金牌会员";
    self.jfGradeLabel.font = FONT_FOURTEEN;
    self.jfGradeLabel.textColor = COLOR_ORG;
    [self.jfView addSubview:self.jfGradeLabel];
    /** 积分数量 */
    self.jfCountLabel = [[UILabel alloc]init];
    self.jfCountLabel.text = @"4444";
    self.jfCountLabel.font = FONT_FOURTEEN;
    self.jfCountLabel.textColor = COLOR_ORG;
    _jfCountLabel.userInteractionEnabled = YES;
    [self.jfView addSubview:self.jfCountLabel];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushIntegralAction)];
    [_jfCountLabel addGestureRecognizer:tap];
    
    /** 签到view */
    self.qdView = [[UIView alloc]init];
    self.qdView.backgroundColor = [UIColor colorWithHex:0xF4F4F4];
    [self.headView addSubview:self.qdView];
    /** 进度条 */
    _stepView = [[XFStepView alloc]initWithFrame:CGRectMake(0, 10, self.view.frame.size.width, 60) Titles:[NSArray arrayWithObjects:@"第一天", @"第二天", @"第三天", @"第四天", @"第五天",@"第六天", @"第七天", nil]];
    [self.qdView addSubview:_stepView];
    
    /** 签到按钮 */
    self.qdButton = [[UIButton alloc]init];
    [self.qdButton addTarget:self action:@selector(qd:) forControlEvents:UIControlEventTouchUpInside];
    self.qdButton.cornerRadius = 5;
    self.qdButton.backgroundColor = COLOR_ORG;
    [self.qdButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.qdButton setTitle:@"签到" forState:UIControlStateNormal];
    [self.qdView addSubview:self.qdButton];
    
}




- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, NAVIGATION_HEIGHT)
    .widthIs(Wi)
    .heightIs(TableViewHeight);
    
    /** 积分view */
    self.jfView.sd_layout
    .leftSpaceToView(self.headView, 0)
    .topSpaceToView(self.headView, 0)
    .rightSpaceToView(self.headView, 0)
    .heightIs(100);
    /** 用户图像 */
    self.userImageView.sd_layout
    .leftSpaceToView(self.jfView, 10)
    .topSpaceToView(self.jfView, 10)
    .widthIs(80)
    .heightIs(80);
    /** 用户名字 */
    self.userNameLabel.sd_layout
    .leftSpaceToView(self.userImageView, 10)
    .centerYEqualToView(self.userImageView)
    .widthIs(80)
    .heightIs(30);
    /** 积分等级 */
    self.jfGradeLabel.sd_layout
    .leftSpaceToView(self.userNameLabel, 10)
    .topEqualToView(self.userNameLabel)
    .widthIs(80)
    .heightIs(30);
    /** 积分数目 */
    self.jfCountLabel.sd_layout
    .rightSpaceToView(self.jfView, 10)
    .topEqualToView(self.userNameLabel)
    .widthIs(80)
    .heightIs(30);
    
    /** 签到view */
    self.qdView.sd_layout
    .leftSpaceToView(self.headView, 0)
    .topSpaceToView(self.jfView, 0)
    .widthIs(SCREEN_WIDTH)
    .heightIs(100);
    self.qdButton.sd_layout
    .bottomSpaceToView(self.qdView, 0)
    .centerXEqualToView(self.qdView)
    .widthIs(100)
    .heightIs(30);
    
    
    
}
#pragma mark - Action

- (void)qd:(UIButton *)btn {
    
    int step = _stepView.stepIndex;
    [_stepView setStepIndex:step + 1 Animation:YES];
}

- (void)setupNavigationItems {
    
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    titleLabel.text = @"积分";
    self.navigationItem.titleView = titleLabel;
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)pushIntegralAction {
    IntegralViewController *vc = [IntegralViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - tableViewDelegate & tableViewDatasorce

//分区头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
        view .backgroundColor = [UIColor whiteColor];
        UILabel *titLable = [[UILabel alloc]init];
        titLable.font = FONT_FOURTEEN;
        titLable.text = @"精品积分换购 ";
        titLable.textColor = COLOR_Gray;
        [view addSubview:titLable];
        titLable.sd_layout
        .leftSpaceToView(view, 10)
        .topSpaceToView(view, 0)
        .widthIs(150)
        .heightIs(30);
        
        
        return view;
    }
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    view .backgroundColor = [UIColor whiteColor];
    UILabel *titLable = [[UILabel alloc]init];
    titLable.text = @"我的关注";
    titLable.font = FONT_FOURTEEN;
    titLable.textColor = COLOR_Gray;
    [view addSubview:titLable];
    titLable.sd_layout
    .leftSpaceToView(view, 10)
    .topSpaceToView(view, 0)
    .widthIs(150)
    .heightIs(30);
    
    
    return view;
}
/** 分区头的高 */
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 30;
}



//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
   
    return 10;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
     return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[AXMyJfTableViewCell class] contentViewWidth:SCREEN_WIDTH];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    AXMyJfTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyJfTableViewCell reuseID] forIndexPath:indexPath];
 
    
    
    
    return cell;
    
    
}



@end
